package com.hn.javamail.controller;

import com.hn.javamail.result.Result;
import com.hn.javamail.service.MailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import java.util.Map;

@RestController
@Api(tags = "邮件模块")
@RequestMapping("/mail")
public class MailController {

    @Resource
    private MailService mailService;

    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "总字段包含以下所有参数,不传", required = false, dataType = "Map"),
            @ApiImplicitParam(name = "mailRecipients", value = "收件人邮箱 可传多个,分割", required = true, dataType = "String"),
            @ApiImplicitParam(name = "title", value = "标题", required = true, dataType = "String"),
            @ApiImplicitParam(name = "content", value = "内容", required = true, dataType = "String")

    })
    @ApiOperation(value = "邮件模块-发送邮件")
    @PostMapping("/sendMail")
    public Result sendMail(@RequestParam Map<String, Object> params) throws MessagingException {
        return mailService.sendMail(params);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "总字段包含以下所有参数,不传", required = false, dataType = "Map"),
            @ApiImplicitParam(name = "usageScenario", value = "使用场景 1.登录 2.密码找回", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "mailRecipients", value = "收件人邮箱", required = true, dataType = "String")
    })
    @ApiOperation(value = "邮箱模块-发送验证码")
    @PostMapping("/sendCode")
    public Result sendCode(@RequestParam Map<String, Object> params) throws MessagingException {
        return mailService.sendCode(params);
    }

}
